//
//  ZZCMeUbiViewController.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCMeUbiViewController.h"
#import "ZZCWithdrawController.h"
#import "ZZCBuyUbiController.h"
#import "ZZCRegularUbiController.h"
#import "ZZCcurrentController.h"

@interface ZZCMeUbiViewController ()
@property (weak,  nonatomic) IBOutlet UILabel *balanceLabel;
@property (assign,nonatomic) int stateType;
@property (retain,nonatomic) NSDictionary *X;
@end

@implementation ZZCMeUbiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的U币";
    [self requestMeUbiData];
    [self requestCashState];
}
- (void)requestMeUbiData {
    NSString *token = ZZCNSUserDefaults(@"token");
    NSDictionary *dict = @{@"token":token};
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,@"token":token};
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_MYUBI parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (error) {
            ZZCLog(@"失败-%@",error);
        }else {
            ZZCLog(@"成功-%@",responseObject);
            self.balanceLabel.text = responseObject[@"data"][@"ubi"];
        }
    }];
}
- (void)requestCashState {
    NSString *token = ZZCNSUserDefaults(@"token");
    NSDictionary *dict = @{@"token":token};
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,@"token":token};
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_WITHDRAW_APPLY parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        _X = responseObject[@""];
        if (error) {
            ZZCLog(@"失败-%@",error);
        }else {
            ZZCLog(@"#####成功-%@",responseObject);
            self.stateType = [responseObject[@"data"][@"apply_status"] intValue];
            NSLog(@"%d",self.stateType);
        }
    }];
}
//购买U币
- (IBAction)buyUbiClick:(id)sender {
    ZZCBuyUbiController *buy = [ZZCBuyUbiController new];
    [self.navigationController pushViewController:buy animated:YES];
}

//转定期
- (IBAction)regularClick {
    ZZCRegularUbiController *reg = [ZZCRegularUbiController new];
     [self.navigationController pushViewController:reg animated:YES];
}
//转账U币
- (IBAction)expendClick {
    ZZCcurrentController *cur = [ZZCcurrentController new];
    [self.navigationController pushViewController:cur animated:YES];
}
//提现
- (IBAction)withdrawClick {
    ZZCWithdrawController *wit = [ZZCWithdrawController new];
    wit.moneyCount = self.balanceLabel.text;
    NSLog(@"%@",wit.moneyCount);
    [self.navigationController pushViewController:wit animated:YES];
}
@end
